synchronized block java

69

synchronized java -

synchronized blocks the next thread's call to method 
 as long as the previous thread's execution is not finished. 
  Threads can access this method one at a time. 
  Without synchronized all threads can access this method simultaneously.

synchronized block java -

public class MyCounter {

  private int count = 0;

  public synchronized void add(int value){
      this.count += value;
  }
}

Comments

Submit
0 Comments